<!DOCTYPE html>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<html>
<head>
<title>${name_china}管理列表</title>
<%@include file="/common/head.jsp" %>

<!-- 时间日期插件 -->
<link href="<%=request.getContextPath()%>/static/plugin/My97DatePicker/skin/default/datepicker.css" rel="stylesheet" >
<script src="<%=request.getContextPath()%>/static/plugin/My97DatePicker/WdatePicker.js"></script>

</head>
<body class="iframe-page">
<div class="page-title-wrapper">
    <div class="page-title">
        <div class="page-title-text">
            <span>${name_china}管理</span>
        </div>
        <div id="toolbar" style="float: right"></div>
    </div>
    <div class="page-title-border"></div>
</div>

<div class="search-field">
    <span class="field-cont">
        <span class="field-cont-title">用户昵称</span>
        <input type="text" class="summer-input" id="userName"/>
    </span>
    
     <span class="field-cont">
        <span class="field-cont-title">发放状态</span>
        <input type="text" class="summer-input" id="isGive"/>
    </span>
    
     <span class="field-cont">
        <span class="field-cont-title">账号名</span>
        <input type="text" class="summer-input" id="zfbName"/>
    </span>
    
     <span class="field-cont">
        <span class="field-cont-title">账号</span>
        <input type="text" class="summer-input" id="zfbAccount"/>
    </span>
    
    <span class="field-cont">
        <span class="field-cont-title">申请开始时间</span>
        <input type="text" class="summer-input" id="startTime" onFocus="WdatePicker({dateFmt:'yyyy-MM-dd'})"/>
    </span>
    
    <span class="field-cont">
        <span class="field-cont-title">申请结束时间</span>
        <input type="text" class="summer-input" id="stopTime" onFocus="WdatePicker({dateFmt:'yyyy-MM-dd',minDate:'#F{$dp.$D(\'startTime\')}'})"/>
    </span>
    
    <br/>
    <span class="field-cont">
        <span class="field-cont-title">发放开始时间</span>
        <input type="text" class="summer-input" id="ffstartTime" onFocus="WdatePicker({dateFmt:'yyyy-MM-dd'})"/>
    </span>
    
    <span class="field-cont">
        <span class="field-cont-title">发放结束时间</span>
        <input type="text" class="summer-input" id="ffstopTime" onFocus="WdatePicker({dateFmt:'yyyy-MM-dd',minDate:'#F{$dp.$D(\'ffstartTime\')}'})"/>
    </span>
    
    <span class="field-btn-wrapper">
        <a id="search" class="btn btn-primary btn-icon wave distance-right"><i class="icon icon-search"></i></a>
        <a id="reset" class="btn btn-icon wave wave-dark"><i class="icon icon-refresh"></i></a>
    </span>
</div>

<div id="t-wrap">
    <table class="summer-datagrid" id="dataList">
	    <thead>
		    <tr>
		        <th>全选<input name="all" type="checkbox" value="" /></th>
		        <th>申请时间</th>
		        <th>用户昵称</th>
		        <th>用户ID</th>
		        <th>提现类型</th>
		        <th>提现金额</th>
		        <th>手续费</th>
		        <th>提现账号名称</th>
		        <th>提现账号</th>
		        <th>发放时间</th>
		        <th>备注</th>
				<th>是否发放</th>
		    </tr>
	    </thead>
    </table>
</div>

<script>
	//请求url
	var CONST_URL = {
		LIST: basePath + '${common_url}list',
	   	INIT_ADD: basePath + "${common_url}initAdd",
	   	INIT_EDIT: basePath + "${common_url}initEdit",
	   	INIT_VIEW: basePath + "${common_url}initView",
	   	INIT_FAFANG: basePath + "${common_url}initFafang",
	   	EXP: basePath + "${common_url}exp",
	   	FAFANG_BATCH: basePath + "${common_url}fafangBatch",
	   	DEL: basePath + "${common_url}delete"
	};
	
    var  permission = CommonUtil.getPermission('${name_english}');
    
    $(function () {
    	
    	$("#isGive").combobox({
    		defaultValue : '0',
    		async:false,
            valueField : 'code',
            textField : 'name',
            url : COMMON_URL.getCode + '?type=T_DM_TIXIAN_ISGIVE'
        });
    	
        // 新建toobar
		$.funcbar({
			id: 'toolbar',
			type: 'toolbar',
			data: permission,
			permit: ['${name_english}:fafangBatch','${name_english}:exp'],
		});
        
        // 查询按钮
        $('#search').on('click', reloadTable);
        
        //重置按钮
        $('#reset').on('click', function () {
        	//重置文本框的值
        	$('#userName').val('');
			$("#isGive").combobox("clear");
			$('#zfbName').val('');
			$('#zfbAccount').val('');
			$('#startTime').val('');
        	$('#stopTime').val('');
        	$('#ffstartTime').val('');
        	$('#ffstopTime').val('');
        	
        	reloadTable();
        });
        
        //新建
        $('#toolbar').on('click', 'a[data-permit="${name_english}:initAdd"]', function() {
        	window.location.href = CONST_URL.INIT_ADD; 	  	
		});
        
        
       createTable();
        
        //查看
        $('#t-wrap').on('click', 'a[data-permit="${name_english}:initView"]', function() {
        	var $this = $(this),
        	    id = $this.closest('tr').find('td[data-field="id"]').attr('data-value');
        	window.location.href = CONST_URL.INIT_VIEW +"?id=" + id;
        });
       
         //查看
        $('#t-wrap').on('click', 'a[data-permit="${name_english}:initFafang"]', function() {
        	var $this = $(this),
        	    id = $this.closest('tr').find('td[data-field="id"]').attr('data-value');
        	window.location.href = CONST_URL.INIT_FAFANG +"?id=" + id;
        });
        
        //编辑
        $('#t-wrap').on('click', 'a[data-permit="${name_english}:initEdit"]', function() {
            var $this = $(this),
                id = $this.closest('tr').find('td[data-field="id"]').attr('data-value');
            window.location.href = CONST_URL.INIT_EDIT + '?id=' + id;
        });	
        
        //删除
		$('#t-wrap').on('click', 'a[data-permit="${name_english}:delete"]', function() {
			var $this = $(this),
			    id = $this.closest('tr').find('td[data-field="id"]').attr('data-value');
			$.sdialog({
				type: 'confirm',
				msg: '您确定要删除选中的记录吗?',
				onConfirm: function(result) {
				    if (result) {
				    	$.sajax({
			                url : CONST_URL.DEL + "?ids=" + id,
			                onLoadSuccess : function() {
			                	 $.stip({
                	                type:'ok',//显示类型 有info、 ok、 danger
                	                text: '删除成功！'    
			                	});
			                	reloadTable();  
			                }
			            });
				    		
				    }	
				}
			});
		});
        
        
		//发货
		$('#t-wrap').on('click', 'a[data-permit="${name_english}:fafang"]', function() {
			  var $this = $(this),
              id = $this.closest('tr').find('td[data-field="id"]').attr('data-value');
              window.location.href = CONST_URL.FAFANG + '?id=' + id;
		});
		
		 //导出 
        $('#toolbar').on('click', 'a[data-permit="${name_english}:exp"]', function() {
        	exp(); 	  	
		});
        
		 
        //批量发放
        $('#toolbar').on('click', 'a[data-permit="${name_english}:fafangBatch"]', function() {
        	fafangBatch();	
		});
        
    });
    
    // 重新加载表格
	function reloadTable() {
		$('#dataList').datagrid('reload',{
            ajax: {
            	param: {
            		"userName": trimSpace($('#userName').val()),
    				"zfbName": trimSpace($('#zfbName').val()),
    				"zfbAccount": trimSpace($('#zfbAccount').val()),
    				"startTime": trimSpace($('#startTime').val()),
                	"stopTime": trimSpace($('#stopTime').val()),
                	"ffstartTime": trimSpace($('#ffstartTime').val()),
                	"ffstopTime": trimSpace($('#ffstopTime').val()),
    				"isGive": $("#isGive").combobox("getValue")
            	}
            }
        });
	}
    
    //创建表格
    function createTable() {
    	$('#dataList').datagrid({
    		ajax: {
    			url: CONST_URL.LIST,
    			param: {
    				"userName": trimSpace($('#userName').val()),
    				"zfbName": trimSpace($('#zfbName').val()),
    				"zfbAccount": trimSpace($('#zfbAccount').val()),
    				"startTime": trimSpace($('#startTime').val()),
                	"stopTime": trimSpace($('#stopTime').val()),
                	"ffstartTime": trimSpace($('#ffstartTime').val()),
                	"ffstopTime": trimSpace($('#ffstopTime').val()),
    				"isGive": $("#isGive").combobox("getValue")
            	}
    		},
    		columns: [
    		     {
    		    	 field: 'id',
    		    	 hidden: true
    		     },
    		     {
    		    	 render: function (rowData) {
    		    		 return '<input name="batch" type="checkbox" value="'+rowData.id+'" />';
    		    	 }
    		     },
    		     {
    		    	 field: 'userName',
    		    	 render: function (rowData) {
    		    		 return '<a href="javascript:;" data-permit="${name_english}:initView" class="link">'+ rowData.userName +'</a>';
    		    	 }
    		     },
    		     {
	   		    	 field: 'createTime'
   		         },
    		     {
    		    	 field: 'userId'
    		     },
    		     {
    		    	 field: 'type'
    		     },
    		     {
    		    	 field: 'money'
    		     },
    		     {
    		    	 field: 'feeMoney'
    		     },
    		     {
    		    	 field: 'zfbName'
    		     },
    		     {
    		    	 field: 'zfbAccount'
    		     },
    		     {
    		    	 field: 'giveTime'
    		     },
    		     {
    		    	 field: 'note'
    		     },
    		    {
    		    	 render: function (rowData) {
    		    		 if( rowData.isGive == "1" ){
    		    			 return "发放成功";
    		    		 }else if( rowData.isGive == "2" ){
    		    			 return "发放失败";
    		    		 }else{
    		    			 return $.funcbar({
        		    			 data: permission,    //请求的数据
        		    			 type: 'text',     //类型
        		    			 display: 3,    //显示数量
        		    			 permit: ['${name_english}:initEdit','${name_english}:initFafang'] //需要的权限按钮
        		    		 });
    		    		 }
    		    		 
    		    	 }
    		    }
    		          
    	    ]
    	});
    }
   
     function fafangBatch(){
    	 
    	var obj=document.getElementsByName('batch'); //选择所有name="'test'"的对象，返回数组 
    	//取到对象数组后，我们来循环检测它是不是被选中 
    	var s=''; 
    	for(var i=0; i<obj.length; i++){ 
    	  if(obj[i].checked) s+=obj[i].value+','; //如果选中，将value添加到变量s中 
    	} 
    	//alert(s.length-1)
    	s=s.substring(0,s.length-1);
    	//那么现在来检测s的值就知道选中的复选框的值了 
    	//alert(s==''?'你还没有选择任何内容！':s); 
    	 
    	var ids=s;
    	 
        var form = document.createElement('form');//创建表单
        form.method = 'post';//表单提交方式
        form.action = CONST_URL.FAFANG_BATCH;//路径
        document.body.appendChild(form);
        
        //全称
        if ( ids ) {
            var inputIds = document.createElement('input');
            inputIds.type = 'hidden';
            inputIds.value = ids;
            inputIds.name = 'ids';
            form.appendChild(inputIds );
        }
        
        if( ids ){
        	$.sdialog({
                type : 'confirm',
                msg : '确定要批量发放选中的记录吗？',
                onConfirm : function(result) {
                    if (result) {
                        form.submit();
                        reloadTable(); 
                    }
                }
            });
        }else{
        	$.stip({
                type:'danger',//显示类型 有info、 ok、 danger
                text: '未选中记录！'    
        	});
        }
         
    	
     }
    
    function exp() {
        //得到查询条件中的value和创建表单
        var userName = trimSpace($('#userName').val()),
        	zfbName = trimSpace($('#zfbName').val()),
        	zfbAccount = trimSpace($('#zfbAccount').val()),
        	startTime = trimSpace($('#startTime').val()),
        	endTime = trimSpace($('#endTime').val()),
        	ffstartTime = trimSpace($('#ffstartTime').val()),
        	ffendTime = trimSpace($('#ffendTime').val()),
        	isGive = $('#isGive').combobox('getValue') ;
        
        var form = document.createElement('form');//创建表单
        form.method = 'post';//表单提交方式
        form.action = CONST_URL.EXP;//路径
        document.body.appendChild(form);

        //创建查询条件(input隐藏)
        //全称
        if ( userName ) {
            var inputUserName = document.createElement('input');
            inputUserName.type = 'hidden';
            inputUserName.value = userName;
            inputUserName.name = 'userName';
            form.appendChild(inputUserName );
        }
        
        if ( zfbName ) {
            var inputZfbName = document.createElement('input');
            inputZfbName.type = 'hidden';
            inputZfbName.value = zfbName;
            inputZfbName.name = 'zfbName';
            form.appendChild(inputZfbName);
        }
        
        if ( zfbAccount ) {
            var inputZfbAccount = document.createElement('input');
            inputZfbAccount.type = 'hidden';
            inputZfbAccount.value = zfbAccount;
            inputZfbAccount.name = 'zfbAccount';
            form.appendChild(inputZfbAccount);
        }
        
        if ( startTime ) {
            var inputStartTime = document.createElement('input');
            inputStartTime.type = 'hidden';
            inputStartTime.value = startTime;
            inputStartTime.name = 'startTime';
            form.appendChild(inputStartTime);
        }
        
        if ( endTime ) {
            var inputEndTime = document.createElement('input');
            inputEndTime.type = 'hidden';
            inputEndTime.value = endTime;
            inputEndTime.name = 'endTime';
            form.appendChild(inputEndTime);
        }
        	
        if ( ffstartTime ) {
            var inputFfstartTime = document.createElement('input');
            inputFfstartTime.type = 'hidden';
            inputFfstartTime.value = ffstartTime;
            inputFfstartTime.name = 'ffstartTime';
            form.appendChild(inputFfstartTime);
        }
        if ( ffendTime ) {
            var inputFfendTime = document.createElement('input');
            inputFfendTime.type = 'hidden';
            inputFfendTime.value = ffendTime;
            inputFfendTime.name = 'ffendTime';
            form.appendChild(inputFfendTime);
        }
        
        if ( isGive ) {
            var inputIsGive = document.createElement('input');
            inputIsGive.type = 'hidden';
            inputIsGive.value = isGive;
            inputIsGive.name = 'isGive';
            form.appendChild(inputIsGive);
        }
        
        
        //如果没有任何条件就提示用户
        if ( userName || zfbName || zfbAccount || startTime || endTime || ffstartTime || ffendTime || isGive ) {
            form.submit();
        } else {
            $.sdialog({
                 type : 'confirm',
                 msg : '未添加导出条件，默认为全部导出，确定吗？',
                 onConfirm : function(result) {
                     if (result) {
                         form.submit();
                     }
                 }
             });
        }
    }
   
</script>
</body>
</html>